﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace HYFloorPipeModule
{
	public partial class FrmConnStyle : System.Windows.Forms.Form
	{
		public FrmConnStyle()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this.userSetting = new HVACUserSetting();
			this.UserSettingRead();
		}

		private void FrmConnStyle_Load(object sender, EventArgs e)
		{
			FloorPipeConnParam floorPipeConn = this.userSetting.GetFloorPipeConn();
			this.txtSC.Text = floorPipeConn.ScDistance.ToString();
			this.txtFP.Text = floorPipeConn.FpDistance.ToString();
			this.txtBT.Text = floorPipeConn.BtDistance.ToString();
		}

		private void UserSettingWrite()
		{
			this.userSetting.WriteTerminalConnectionType(this.connType.ToString());
		}

		private void UserSettingRead()
		{
			if (this.userSetting.GetTerminalConnectionType() == "0")
			{
				this.rboDirectConn.Checked = true;
				this.rboTrackConn.Checked = false;
				return;
			}
			this.rboDirectConn.Checked = false;
			this.rboTrackConn.Checked = true;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void btnSure_Click(object sender, EventArgs e)
		{
			if (this.rboTrackConn.Checked)
			{
				this.connType = 1;
			}
			this.UserSettingWrite();
			FloorPipeConnParam settingParam = this.GetSettingParam();
			this.userSetting.WriteFloorPipeConn(settingParam);
			base.DialogResult = DialogResult.OK;
		}

		public int GetConnStyle()
		{
			if (this.rboTrackConn.Checked)
			{
				return 1;
			}
			return 0;
		}

		public FloorPipeConnParam GetSettingParam()
		{
			return new FloorPipeConnParam
			{
				ScDistance = Convert.ToInt32(this.txtSC.Text),
				FpDistance = Convert.ToInt32(this.txtFP.Text),
				BtDistance = Convert.ToInt32(this.txtBT.Text)
			};
		}

		private void txtSC_Validating(object sender, CancelEventArgs e)
		{
			YJKTextBox hytextBox = sender as YJKTextBox;
			if (hytextBox == null)
			{
				return;
			}
			int num = Convert.ToInt32(hytextBox.Text);
			string name = hytextBox.Name;
			if (!(name == "txtSC"))
			{
				if (!(name == "txtFP"))
				{
					if (!(name == "txtBT"))
					{
						return;
					}
					if (num < 15 || num > 2000)
					{
						YJKMessageBox.Information("盘管连接线间的距离，\n应在15-2000之间。");
						e.Cancel = true;
					}
				}
				else if (num < 0 || num > 20000)
				{
					YJKMessageBox.Information("地热盘管处出口连接线，\n应在0-20000之间。");
					e.Cancel = true;
					return;
				}
			}
			else if (num < 100 || num > 20000)
			{
				YJKMessageBox.Information("分集水器处出口连接线，\n应在100-20000之间。");
				e.Cancel = true;
				return;
			}
		}

		private int connType;

		private HVACUserSetting userSetting = new HVACUserSetting();
	}
}
